<html>
<head><meta charset="utf-8"><title>Why isn’t Name optional? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html">Why isn’t Name optional?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222666352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222666352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aramis Razzaghipour <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222666352">(Jan 14 2021 at 00:21)</a>:</h4>
<p>The <code>name</code> field of items from <a href="http://item_tree.rs">item_tree.rs</a> is never an <code>Option&lt;Name&gt;</code>. Why is this? When lowering to HIR from AST, the name could be missing from the AST. Take <code>Struct</code> as an example: <code>lower::Ctx::lower_struct</code> returns an <code>Option&lt;FileItemTreeId&lt;Struct&gt;&gt;</code>, and only returns <code>None</code> if the name is not present in the AST. Why not salvage the lowering and make <code>name</code> optional, rather than throwing the entire <code>Struct</code> away?</p>



<a name="222670786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222670786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222670786">(Jan 14 2021 at 01:22)</a>:</h4>
<p>What could we do with that struct?</p>



<a name="222677579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222677579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aramis Razzaghipour <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222677579">(Jan 14 2021 at 03:54)</a>:</h4>
<p>I’m not sure, it just seems better not to throw away data. I guess it isn’t really useful though.</p>



<a name="222836205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836205">(Jan 15 2021 at 09:31)</a>:</h4>
<p>yeah, the situation with optionality of names is a mess</p>



<a name="222836278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836278">(Jan 15 2021 at 09:32)</a>:</h4>
<p>ther's also <code>Name::missing</code>, so even a non-optional name might not be there</p>



<a name="222836406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836406">(Jan 15 2021 at 09:33)</a>:</h4>
<p>I think we should probably keep this simple -- remove the missing and options, and just through the defs away when the ast doesn't have a name</p>



<a name="222836596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836596">(Jan 15 2021 at 09:35)</a>:</h4>
<p>the way the parser works, it the name's missing, there's probably little else in the def anyways</p>



<a name="222836768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836768">(Jan 15 2021 at 09:37)</a>:</h4>
<p>Hm, <span class="user-mention" data-user-id="211727">@Jonas Schievink</span> , I think I've just found a pile of dead code!</p>



<a name="222836836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836836">(Jan 15 2021 at 09:38)</a>:</h4>
<p>Take a look at <code>lower_enum</code> in <code>adt.rs</code></p>



<a name="222836845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836845">(Jan 15 2021 at 09:38)</a>:</h4>
<p>The</p>



<a name="222836870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836870">(Jan 15 2021 at 09:38)</a>:</h4>
<div class="codehilite"><pre><span></span><code>            || EnumVariantData {
                name: var.name().map_or_else(Name::missing, |it| it.as_name()),
                variant_data: Arc::new(VariantData::new(db, ast.with_value(var.kind()), module_id)),
            },
</code></pre></div>
<p>bit I think is dead -- this is now handled by item tree?</p>



<a name="222836962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Why%20isn%E2%80%99t%20Name%20optional%3F/near/222836962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Why.20isn.E2.80.99t.20Name.20optional.3F.html#222836962">(Jan 15 2021 at 09:39)</a>:</h4>
<p>I wonder if the whole <code>Trace</code> infra can be removed?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>